package com.shop.front.dao.store;

import com.shop.jpa.BaseDao;
import com.shop.domain.store.StoreCart;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface StoreCartDao extends BaseDao<StoreCart, Long> {

    //@Query("from StoreCart where isPay = 0 and uid = ?1 and productId = ?2 and productAttrValueId = ?3")
    @Query(nativeQuery = true, value = "select * from t_store_cart where is_pay = 0 and uid = ?1 and product_id = ?2 and product_attr_value_id = ?3 limit 1")
    public StoreCart findByProduct(Long userId, Long productId, Long productAttrValueId);

    @Modifying(clearAutomatically = true)
    @Query("update StoreCart set cartNum = cartNum + ?2 where id = ?1")
    public int addCartNum(Long id, Integer cartNum);

    @Modifying(clearAutomatically = true)
    @Query("update StoreCart set cartNum = ?2 where id = ?1")
    public int updateCartNum(Long id, Integer cartNum);

    @Modifying(clearAutomatically = true)
    @Query("update StoreCart set isPay = ?2 where id = ?1")
    public int updateIsPay(Long id, Integer isPay);
}
